home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / GetPPPStatus / TrapUtils.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.5 KB  |  112 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TrapUtils.c
  3.  
  4.     Contains:    Functions to help you when you are building and sending Apple events.
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/22/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. //    System includes
  24. #include <OSUtils.h>
  25. #include <Traps.h>
  26.  
  27. //    Utility routines
  28. #include "TrapUtils.h"
  29.  
  30.  
  31. // ===============================================================================
  32.  
  33. static pascal UInt16 CountToolboxTraps( void )
  34. {
  35.     static UInt16 trapCount;
  36.     
  37.     if ( !trapCount )
  38.     {
  39.         if ( GetToolTrapAddress( _InitGraf ) == GetToolTrapAddress( 0xAA6E ) )
  40.         {
  41.             trapCount = 0x0200;
  42.         }
  43.         else
  44.         {
  45.             trapCount = 0x0400;
  46.         }
  47.     }
  48.     
  49.     return trapCount;
  50. }
  51.  
  52. // ===============================================================================
  53.  
  54. static pascal TrapType GetTrapType( UInt16 trapWord )
  55. {
  56.     if ( trapWord & 0x0800 )
  57.     {
  58.         return ToolTrap;
  59.     }
  60.     else
  61.     {
  62.         return OSTrap;
  63.     }
  64. }
  65.  
  66. // ===============================================================================
  67.  
  68. pascal Boolean TrapAvailable( UInt16 trapWord )
  69. {
  70.     if ( GetTrapType( trapWord ) == OSTrap )
  71.     {
  72.         return GetToolTrapAddress( _Unimplemented ) != GetOSTrapAddress( trapWord );
  73.     }
  74.     else if ( ( trapWord & 0x07FF ) >= CountToolboxTraps () )
  75.     {
  76.         return false;
  77.     }
  78.     else
  79.     {
  80.         return GetToolTrapAddress( _Unimplemented ) != GetToolTrapAddress ( trapWord );
  81.     }
  82. }
  83.  
  84. // ===============================================================================
  85.  
  86. pascal void * MyGetTrapAddress( UInt16 trapWord )
  87. {
  88.     if ( GetTrapType( trapWord ) == OSTrap )
  89.     {
  90.         return GetOSTrapAddress( trapWord );
  91.     }
  92.     else
  93.     {
  94.         return GetToolTrapAddress( trapWord );
  95.     }
  96. }
  97.  
  98. // ===============================================================================
  99.  
  100. pascal void MySetTrapAddress( UInt16 trapWord, void *newAddr )
  101. {
  102.     if ( GetTrapType( trapWord ) == OSTrap )
  103.     {
  104.         SetOSTrapAddress( newAddr, trapWord );
  105.     }
  106.     else
  107.     {
  108.         SetToolTrapAddress( newAddr, trapWord );
  109.     }
  110. }
  111.  
  112.